package example.collections;

import java.util.Collections;
import java.util.Set;
import java.util.TreeSet;

/**
 * Created by lenovo on 2016/11/7 0007.
 * 将字符串转换为集合并使用 Collection 类的 Collection.min() 和 Collection.max() 来比较集合中的元素
 */
public class Compare {
    public static void main(String[] args) {
        String[] coins = {"Penny", "nickel", "dime",
                "Quarter", "dollar"};
        Set<String> set = new TreeSet<String>();
//        for (int i = 0; i < coins.length; i++) {
//            set.add(coins[i]);
//        }
        Collections.addAll(set, coins);
        System.out.println(Collections.min(set));//比较的是各个元素的ascii码表中的数字代码大小???
        //获取最小元素，忽略字母大小写
        System.out.println(Collections.min(set, String.CASE_INSENSITIVE_ORDER));
        System.out.println("===================================================");
        System.out.println(Collections.max(set));
        System.out.println(Collections.max(set, String.CASE_INSENSITIVE_ORDER));
    }
}
